package com.example.demo_news.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

//用户登录信息表，用于用户登录,可使用邮箱登录或用户名登录
//用户表与个人信息表单向一对一
//用户表与公众号表单向一对一
@Entity
@Table(name="user")
@JsonIgnoreProperties(value = { "hibernateLazyInitializer"})
public class MyUser {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    //主键自增
    private String username;
    //用户账号
    private String email;
    //用户邮箱
    private String password;
    //用户密码
    public Integer getId() {
        return id;
    }
    public String role;
    //用户权限
	@JoinColumn(
        name = "personId",
        referencedColumnName = "id",
        unique= true
        )
    @JsonIgnore//如果A对象持有B的引用，B对象持有A的引用，这样就形成了循环引用，如果直接使用json转换会报错
    @OneToOne(
        fetch = FetchType.LAZY,
        targetEntity = Person.class,
        cascade = CascadeType.ALL
    )
    private Person person;

    @JoinColumn(
        name = "officialAccountId",
        referencedColumnName = "id",
        unique= true
        )
    @JsonIgnore//如果A对象持有B的引用，B对象持有A的引用，这样就形成了循环引用，如果直接使用json转换会报错
    @OneToOne(
        fetch = FetchType.LAZY,
        targetEntity = OfficialAccount.class,
        cascade = CascadeType.ALL
    )
    private OfficialAccount officialAccount;

    public void setId(Integer id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public Person getPerson() {
        return person;
    }
    public void setPerson(Person person) {
        this.person = person;
    }
    public OfficialAccount getOfficialAccount() {
        return officialAccount;
    }
    public void setOfficialAccount(OfficialAccount officialAccount) {
        this.officialAccount = officialAccount;
    }
    public String getRole() {
        return role;
    }
    public void setRole(String role) {
        this.role = role;
    }
    
}
